package com.mymarkdown.app.websocket.handler;

import com.mymarkdown.app.common.ChainHandlerResult;
import com.mymarkdown.app.websocket.enums.MessageTypeEnum;
import com.mymarkdown.app.websocket.interfaces.HandlerMessage;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import javax.websocket.Session;

/**
 * @author zenglun
 * @date 2021/12/6 2:01 上午
 * @description: TODO 加载上一次历史打开文档MD内容,待完成...
 */
@Slf4j
@Component
public class LoadHistoryMdBody implements HandlerMessage {
    @Override
    public ChainHandlerResult onMessage(String message, Session session) {
        //开始打开最近操作的数据
//        ReentrantLock readUserLatelyOperationLock = LocksUtil.getReadUserLatelyOperationLock();
//        readUserLatelyOperationLock.lock();
//        try {
//            LocksUtil.getReadUserLatelyOperationCondition().await();
//            TimeUnit.MICROSECONDS.sleep(1000);
//        } catch (InterruptedException e) {
//            e.printStackTrace();
//        } finally {
//            readUserLatelyOperationLock.unlock();
//        }
//        boolean flag = CurrentUserUtil.getSelf().sendMessage(JSON.toJSONString(FxApplication.getLatelyOperationMdBodyMessage()));
//        if (flag){
//            //设置当前操作的用户文件
//            try {
//                CurrentUserUtil.getSelf().getOperationFile().put(new File(CurrentUserUtil.getSelf().getUserLatelyInfo().getLatelyOperationFile()));
//            } catch (InterruptedException e) {
//                e.printStackTrace();
//            }
//        }
        return ChainHandlerResult.empty().setResult(true);
    }

    @Override
    public MessageTypeEnum getHandlerType() {
        return MessageTypeEnum.LOAD_HISTORY_MD_BODY;
    }
}
